<?php
namespace app\login\controller;

error_reporting(E_ALL ^ E_NOTICE);
use app\XDeode;
use think\Db;
use think\Controller;
class Sms extends Controller
{
    public function sms(){
$_var_482 = input();

        $_var_483 = $_var_482['key'];
		if ($_var_483 == 'ikmovie.xyz') {

$msg='test';
// $msg = $_var_482['msg'];
// if (!isset($msg)) {
//     return json(['code' => '0', 'msg' => '消息不能为空']);
// }

/*
*type reg/check
*phone 手机号
*/

$code = isset($_var_482['code']) ? $_var_482['code'] : '0000';

if($_var_482['code'] < 1){
	return json(['code' => '0', 'msg' => 'code参数必须为数字']);
}

if(mb_strlen($msg)>50){
	return json(['code' => '0', 'msg' => 'msg参数过长']);
}
$phone = $_var_482['phone'];

if(!preg_match("/^1[34578]\d{9}$/", $phone)){
    return json(['code' => '0', 'msg' => '手机号码不合法']);
}

$retmsg = '';
//短信缓存配置

include APP_PATH.'../extend/alisms' . "/sendSms.php";
if (\Aliyun\DySDKLite\Sms\sendSms(2, $phone, $code, $msg)) {
    $_var_202['code'] = $code;
    $_var_202['phone'] = $phone;
    $_var_202['add_time'] = time();
	db('smslog')->insert($_var_202);
    $retmsg = json(['code' => '200', 'msg' => '短信发送成功']);
} else {
    $retmsg = json(['code' => '200', 'msg' => '短信发送失败，请稍后再试！']);
}
return $retmsg;
}else{
		    return json(['code' => '0', 'msg' => '安全码错误']);
		}
    }
    
}